Hack The Box



Targets

Targets are unique operating system identifiers taken from the versions of those specific operating systems which adapt the selected exploit module to run on that particular version of the operating system. The show targets command issued within an exploit module view will display all available vulnerable targets for that specific exploit, while issuing the same command in the root menu, outside of any selected exploit module, will let us know that we need to select an exploit module first.

MSF - Show Targets

          msf6 > show targets
          [-] No exploit module selected.
        

When looking at our previous exploit module, this would be what we see:

          msf6 exploit(windows/smb/ms17_010_psexec) > options

            Name                  Current Setting                          Required  Description
            ----                  ---------------                          --------  -----------
            DBGTRACE              false                                    yes       Show extra debug trace info
            LEAKATTEMPTS          99                                       yes       How many times to try to leak transaction
            NAMEDPIPE                                                      no        A named pipe that can be connected to (leave blank for auto)
            NAMED_PIPES           /usr/share/metasploit-framework/data/wo  yes       List of named pipes to check
                                   rdlists/named_pipes.txt
            RHOSTS                10.10.10.40                              yes       The target host(s), see https://github.com/rapid7/metasploit-framework
                                                                                      /wiki/Using-Metasploit
            RPORT                 445                                      yes       The Target port (TCP)
            SERVICE_DESCRIPTION                                            no        Service description to to be used on target for pretty listing
            SERVICE_DISPLAY_NAME                                           no        The service display name
            SERVICE_NAME                                                   no        The service name
            SHARE                 ADMIN$                                   yes       The share to connect to, can be an admin share (ADMIN$,C$,...) or a no
                                                                                      rmal read/write folder share
            SMBDomain             .                                        no        The Windows domain to use for authentication
            SMBPass                                                        no        The password for the specified username
            SMBUser                                                        no        The username to authenticate as

          Payload options (windows/meterpreter/reverse_tcp):

            Name      Current Setting  Required  Description
            ----      ---------------  --------  -----------
            EXITFUNC  thread           yes       Exit technique (Accepted: '', seh, thread, process, none)
            LHOST                      yes       The listen address (an interface may be specified)
            LPORT     4444             yes       The listen port

          Exploit target:

            Id  Name
            --  ----
            0   Automatic
        

Selecting a Target

We can see that there is only one general type of target set for this type of exploit. What if we change the exploit module to something that needs more specific target ranges? The following exploit is aimed at:

MS12-063 Microsoft Internet Explorer execCommand Use-After-Free Vulnerability.

If we want to find out more about this specific module and what the vulnerability behind it does, we can use the info command. This command can help us out whenever we are unsure about the origins or functionality of different exploits or auxiliary modules. Keeping in mind that it is always considered best practice to audit our code for any artifact generation or 'additional features', the info command should be one of the first steps we take when using a new module. This way, we can familiarize ourselves with the exploit functionality while assuring a safe, clean working environment for both our clients and us.

MSF - Target Selection

          msf6 exploit(windows/browser/ie_execcommand_uaf) > info

                 Name: MS12-063 Microsoft Internet Explorer execCommand Use-After-Free Vulnerability 
               Module: exploit/windows/browser/ie_execcommand_uaf
             Platform: Windows
                 Arch: 
           Privileged: No
              License: Metasploit Framework License (BSD)
                 Rank: Good
            Disclosed: 2012-09-14

          Provided by:
            unknown
            eromang
            binjo
            sinn3r "sinn3r@metasploit.com"
            juan vazquez "juan.vazquez@metasploit.com"

          Available targets:
            Id  Name
            --  ----
            0   Automatic
            1   IE 7 on Windows XP SP3
            2   IE 8 on Windows XP SP3
            3   IE 7 on Windows Vista
            4   IE 8 on Windows Vista
            5   IE 8 on Windows 7
            6   IE 9 on Windows 7

          Check supported:
            No

          Basic options:
            Name       Current Setting  Required  Description
            ----       ---------------  --------  -----------
            OBFUSCATE  false            no        Enable JavaScript obfuscation
            SRVHOST    0.0.0.0          yes       The local host to listen on. This must be an address on the local machine or 0.0.0.0
            SRVPORT    8080             yes       The local port to listen on.
            SSL        false            no        Negotiate SSL for incoming connections
            SSLCert                     no        Path to a custom SSL certificate (default is randomly generated)
            URIPATH                     no        The URI to use for this exploit (default is random)

          Payload information:

          Description:
            This module exploits a vulnerability found in Microsoft Internet 
            Explorer (MSIE). When rendering an HTML page, the CMshtmlEd object 
            gets deleted in an unexpected manner, but the same memory is reused 
            again later in the CMshtmlEd::Exec() function, leading to a 
            use-after-free condition. Please note that this vulnerability has 
            been exploited since Sep 14, 2012. Also, note that 
            presently, this module has some target dependencies for the ROP 
            chain to be valid. For WinXP SP3 with IE8, msvcrt must be present 
            (as it is by default). For Vista or Win7 with IE8, or Win7 with IE9, 
            JRE 1.6.x or below must be installed (which is often the case).

          References:
            https://cvedetails.com/cve/CVE-2012-4969/
            OSVDB (85532)
            https://docs.microsoft.com/en-us/security-updates/SecurityBulletins/2012/MS12-063
            http://technet.microsoft.com/en-us/security/advisory/2757760
            http://eromang.zataz.com/2012/09/16/zero-day-season-is-really-not-over-yet/
        

Looking at the description, we can get a general idea of what this exploit will accomplish for us. Keeping this in mind, we would next want to check which versions are vulnerable to this exploit.

          msf6 exploit(windows/browser/ie_execcommand_uaf) > options

          Module options (exploit/windows/browser/ie_execcommand_uaf):

            Name       Current Setting  Required  Description
            ----       ---------------  --------  -----------
            OBFUSCATE  false            no        Enable JavaScript obfuscation
            SRVHOST    0.0.0.0          yes       The local host to listen on. This must be an address on the local machine or 0.0.0.0
            SRVPORT    8080             yes       The local port to listen on.
            SSL        false            no        Negotiate SSL for incoming connections
            SSLCert                     no        Path to a custom SSL certificate (default is randomly generated)
            URIPATH                     no        The URI to use for this exploit (default is random)

          Exploit target:

            Id  Name
            --  ----
            0   Automatic

          msf6 exploit(windows/browser/ie_execcommand_uaf) > show targets

          Exploit targets:

            Id  Name
            --  ----
            0   Automatic
            1   IE 7 on Windows XP SP3
            2   IE 8 on Windows XP SP3
            3   IE 7 on Windows Vista
            4   IE 8 on Windows Vista
            5   IE 8 on Windows 7
            6   IE 9 on Windows 7
        

We see options for both different versions of Internet Explorer and various Windows versions. Leaving the selection to Automatic will let msfconsole know that it needs to perform service detection on the given target before launching a successful attack.

If we, however, know what versions are running on our target, we can use the set target "index no." command to pick a target from the list.

          msf6 exploit(windows/browser/ie_execcommand_uaf) > show targets

          Exploit targets:

            Id  Name
            --  ----
            0   Automatic
            1   IE 7 on Windows XP SP3
            2   IE 8 on Windows XP SP3
            3   IE 7 on Windows Vista
            4   IE 8 on Windows Vista
            5   IE 8 on Windows 7
            6   IE 9 on Windows 7

          msf6 exploit(windows/browser/ie_execcommand_uaf) > set target 6

          target => 6
        

Target Types

There is a large variety of target types. Every target can vary from another by service pack, OS version, and even language version. It all depends on the return address and other parameters in the target or within the exploit module.

The return address can vary because a particular language pack changes addresses, a different software version is available, or the addresses are shifted due to hooks. It is all determined by the type of return address required to identify the target. This address can be jmp esp, a jump to a specific register that identifies the target, or a pop/pop/ret. For more on the topic of return addresses, see the Stack-Based Buffer Overflows on Windows x86 module. Comments in the exploit module's code can help us determine what the target is defined by.

To identify a target correctly, we will need to:

  • Obtain a copy of the target binaries
  • Use msfpescan to locate a suitable return address

Later in the module, we will be delving deeper into exploit development, payload generation, and target identification.